<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="com.sundy.core.*"%>
<%@page import="com.sundy.service.*"%>
<%@page import="com.sundy.tools.WebUtility"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	Context context = Utility.obtainContext(request);
	SubjectTbl subject = (SubjectTbl) request.getAttribute("subject");
	DescriptTbl item = (DescriptTbl) request.getAttribute("item");
	List<StudentTbl> list = (List<StudentTbl>) request
			.getAttribute("lst");
	Boolean isViewEx = (Boolean) request.getAttribute("isview");
	boolean isAdmin = context.getCurrentUser().getAdmin() == 1;
	boolean isView = false;
	if (isAdmin)
		isView = false;
	else
		isView = isViewEx;
	if (isView)
		request.setAttribute("title", "登分表 - 已完毕");
	else
		request.setAttribute("title", "登分表");
	String max = (String) request.getAttribute("max");
%>

<jsp:include flush="true" page="/head.jsp"></jsp:include>
<%
	if (isView) {
%>
<div id="mgr" class="center">
	<p>
		&nbsp;
	</p>
	<div class="center">
		<h2><%=item.getCaption()%>
			-
			<%=WebUtility.getRawSubjectCaption(subject
								.getCaption())%></h2>
	</div>
	<table style="border: 1px solid #cccccc; width: 100%; font-size: 16px;">
		<tr>
			<td>
				序号
			</td>
			<td>
				考场
			</td>
			<td>
				班级
			</td>
			<td>
				姓名
			</td>
			<td>
				考号
			</td>
			<td>
				考场地点
			</td>
			<td><%=WebUtility.getRawSubjectCaption(subject
								.getCaption())%>
				分数
			</td>
		</tr>
		<%
			int i = 1;
				for (StudentTbl itm : list) {
		%>
		<tr <%if (i % 2 == 0) {
						out.print("class='even'");
					}%>>
			<td><%=i%></td>
			<td>
				<%=WebUtility.getNondotString(itm.getAddress())%>
			</td>
			<td>
				<%=WebUtility.getNondotString(itm.getClass_())%>
			</td>
			<td>
				<%=itm.getName()%>
			</td>
			<td>
				<%=WebUtility.getNondotString(itm.getNumber())%>
			</td>
			<td>
				<%=WebUtility.getNondotString(itm.getExamRoom())%>
			</td>
			<td>
				<%=WebUtility.getStudentScore(itm, subject)%>
			</td>
		</tr>
		<%
			i++;
				}
		%>
		<tr>
			<td colspan="7" align="center">
				<b>注意：该登分表科目已经输入完毕，不能再编辑了，如果需要修改分数，请与管理员联系</b>
			</td>
		</tr>
	</table>
	</form>
</div>
<p>
	&nbsp;
</p>
<%
	} else {
%>
<script type="text/javascript">
<!--
function keepalive() {
	$.get("<%=path%>/mgr/update?action=keepalive");
}

function scoresubmit() {
  $("#updateform").submit();
}

function scoresubmitex() {
  $("#finished").val("1");
  $("#updateform").submit();
}

$(function() {
    for (var i=0; i < <%=list.size()%>; i++) {
    	$("#sc" + i).keydown(function(event){
  		if (event.keyCode == 13) {
  		    var _txt = $.trim(this.value);
  		    if (_txt != "") {
  		      if (!(/^\d{1,3}$/.test(_txt))) {
  		        alert("输入的数据不是合法数据！");
  		        this.value = "";
  		        return;
  		      } else {
  		        var numb = parseInt(_txt);
  		        if (numb > <%=max%>) {
  		          alert("输入的分数超过<%=max%>?貌似不对哟！");
  		          return;
  		        }
  		      }
  		    }
   			var step = this.id.substr(2, this.id.length);
   			var index = parseInt(step) + 1;
   			$("#sc" + index).focus(); 
  		}
});
    }
	setInterval("keepalive()", 120000);
});
-->
</script>

<div id="mgr" class="center">
	<p>
		&nbsp;
	</p>
	<div class="center">
		<h2><%=item.getCaption()%>
			-
			<%=WebUtility.getRawSubjectCaption(subject
								.getCaption())%></h2>
	</div>
	<form action="<%=path%>/mgr/update" method="post" id="updateform">
		<input type="hidden" name="action" value="update" />
		<input type="hidden" name="subject" value="<%=subject.getId()%>" />
		<input type="hidden" id="finished" name="finished" value="0" />
		<input type="hidden" name="desc" value="<%=item.getId()%>" />
		<table
			style="border: 1px solid #cccccc; width: 100%; font-size: 16px;">
			<tr>
				<td>
					序号
				</td>
				<td>
					考场
				</td>
				<td>
					班级
				</td>
				<td>
					姓名
				</td>
				<td>
					考号
				</td>
				<td>
					考场地点
				</td>
				<td><%=WebUtility.getRawSubjectCaption(subject
								.getCaption())%>
					分数
				</td>
			</tr>
			<%
				int i = 1;
					for (StudentTbl itm : list) {
			%>
			<tr <%if (i % 2 == 0) {
						out.print("class='even'");
					}%>>
				<td><%=i%></td>
				<td>
					<%=WebUtility.getNondotString(itm.getAddress())%>
				</td>
				<td>
					<%=WebUtility.getNondotString(itm.getClass_())%>
				</td>
				<td>
					<%=itm.getName()%>
				</td>
				<td>
					<%=WebUtility.getNondotString(itm.getNumber())%>
				</td>
				<td>
					<%=WebUtility.getNondotString(itm.getExamRoom())%>
				</td>
				<td>
					<input type="text" name="student<%=itm.getId()%>"
						value="<%=WebUtility.getStudentScore(itm, subject)%>"
						id="sc<%=i%>" onkeydown="qkeydown(<%=i%>);" />
				</td>
			</tr>
			<%
				i++;
					}
			%>
			<tr>
				<td colspan="7" align="center">
					<b>注意：点击提交按钮，该登分表将被封存，再也不能编辑了</b>
					<input type="button" value="提交" onclick="scoresubmitex();" />
				</td>
			</tr>
		</table>
	</form>
	<%
		if (isViewEx && isAdmin) {
	%>
	<table style="border: 1px solid #cccccc; width: 100%; font-size: 16px;">
		<tr>
			<td colspan="7" align="center">
				<form action="<%=path%>/mgr/update" method="post">
					<input type="hidden" name="action" value="resetsubject" />
					<input type="hidden" name="subject" value="<%=subject.getId()%>" />
					<input type="hidden" id="finished" name="finished" value="0" />
					<input type="hidden" name="desc" value="<%=item.getId()%>" />
					<input type="submit" value="重新启用该科目" />
				</form>
			</td>
		</tr>
	</table>
	<%
		}
	%>
</div>
<div id="lefttool">
	<table border="0" width="160px">
		<tr>
			<td>
				<span style="color: red; font-size: 12px;">注意随时保存当前的工作哟</span>
				<br />
				输入分数后直接回车可以切换到下一个输入
			</td>
		</tr>
		<tr>
			<td align="right">
				<input type="button" value="保存当前分数表" onclick="scoresubmit();" />
			</td>
		</tr>
	</table>
</div>
<p>
	&nbsp;
</p>
<%
	}
%>
<jsp:include page="footer.jsp"></jsp:include>